/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GerenciarReservas.java
 *
 * Created on Jul 15, 2011, 4:41:07 PM
 */

package janelas;

import classes.Reserva;
import classes.Sala;
import db.ReservaDAO;
import db.SalaDAO;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import projetofinaltecnicas.Main;

/**
 * 
 * @author Wagner
 */

public class GerenciarReservas extends javax.swing.JPanel {

    int idSolic;
    String[] horario = {"08:00-09:50","10:00-11:50","11:50-13:30","13:30-15:20","15:30-17:20","17:30-19:20","19:30-21:20"};
    String[] headerSala = new String[8];
    
    String idioma;
    String usuario;
    /** Creates new form GerenciarReservas */
    public GerenciarReservas(String idioma, String usuario) {
        initComponents();

        this.idioma = idioma;
        this.usuario = usuario;

        jiduser.setText(usuario);
        internacionaliza();
        organizarHeaders();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        popsala = new javax.swing.JPopupMenu();
        salaConfirmar = new javax.swing.JMenuItem();
        salaCancelar = new javax.swing.JMenuItem();
        titulo = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jiduser = new javax.swing.JLabel();
        juser = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        tabsala = new javax.swing.JTable();
        titulosalas = new javax.swing.JLabel();
        confirmarSala = new javax.swing.JButton();
        cancelarSala = new javax.swing.JButton();
        jScrollPane5 = new javax.swing.JScrollPane();
        tabsala1 = new javax.swing.JTable();
        tituloconfirmadas = new javax.swing.JLabel();

        salaConfirmar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/tick.png"))); // NOI18N
        salaConfirmar.setLabel("Confirmar");
        salaConfirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salaConfirmarActionPerformed(evt);
            }
        });
        popsala.add(salaConfirmar);

        salaCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/cross.png"))); // NOI18N
        salaCancelar.setText("Negar");
        salaCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salaCancelarActionPerformed(evt);
            }
        });
        popsala.add(salaCancelar);

        setMinimumSize(new java.awt.Dimension(776, 552));
        setSize(new java.awt.Dimension(776, 552));
        addContainerListener(new java.awt.event.ContainerAdapter() {
            public void componentAdded(java.awt.event.ContainerEvent evt) {
                formComponentAdded(evt);
            }
        });
        addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                formAncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });

        titulo.setFont(new java.awt.Font("Lucida Grande", 1, 13)); // NOI18N
        titulo.setText("Verificar Solicitações");

        jiduser.setText("ID User");

        juser.setFont(new java.awt.Font("Lucida Grande", 1, 13));
        juser.setText("Usuário");

        tabsala.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID Solic", "ID Sala", "ID User", "N Lugares", "Local", "TIpo", "Data", "Horário"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Integer.class, java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabsala.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tabsala.setShowGrid(true);
        tabsala.setShowHorizontalLines(false);
        tabsala.getTableHeader().setReorderingAllowed(false);
        tabsala.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabsalaMouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(tabsala);
        tabsala.getColumnModel().getColumn(0).setResizable(false);
        tabsala.getColumnModel().getColumn(1).setResizable(false);
        tabsala.getColumnModel().getColumn(2).setResizable(false);
        tabsala.getColumnModel().getColumn(3).setResizable(false);
        tabsala.getColumnModel().getColumn(4).setResizable(false);
        tabsala.getColumnModel().getColumn(5).setResizable(false);
        tabsala.getColumnModel().getColumn(6).setResizable(false);
        tabsala.getColumnModel().getColumn(7).setResizable(false);

        titulosalas.setText("Salas");

        confirmarSala.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/tick.png"))); // NOI18N
        confirmarSala.setText("Confirmar");
        confirmarSala.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                confirmarSalaActionPerformed(evt);
            }
        });

        cancelarSala.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/cross.png"))); // NOI18N
        cancelarSala.setText("Negar");
        cancelarSala.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarSalaActionPerformed(evt);
            }
        });

        tabsala1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID Solic", "ID Sala", "ID User", "N Lugares", "Local", "TIpo", "Data", "Horário"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabsala1.setShowGrid(true);
        tabsala1.setShowHorizontalLines(false);
        tabsala1.getTableHeader().setReorderingAllowed(false);
        jScrollPane5.setViewportView(tabsala1);
        tabsala1.getColumnModel().getColumn(0).setResizable(false);
        tabsala1.getColumnModel().getColumn(1).setResizable(false);
        tabsala1.getColumnModel().getColumn(2).setResizable(false);
        tabsala1.getColumnModel().getColumn(3).setResizable(false);
        tabsala1.getColumnModel().getColumn(4).setResizable(false);
        tabsala1.getColumnModel().getColumn(5).setResizable(false);
        tabsala1.getColumnModel().getColumn(6).setResizable(false);
        tabsala1.getColumnModel().getColumn(7).setResizable(false);

        tituloconfirmadas.setText("Reservas Confirmadas");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jScrollPane5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 740, Short.MAX_VALUE)
                        .addContainerGap())
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 740, Short.MAX_VALUE)
                            .add(layout.createSequentialGroup()
                                .add(titulo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 190, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 276, Short.MAX_VALUE)
                                .add(juser)
                                .add(18, 18, 18)
                                .add(jiduser)
                                .add(158, 158, 158)))
                        .add(20, 20, 20))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jScrollPane4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 740, Short.MAX_VALUE)
                            .add(layout.createSequentialGroup()
                                .add(titulosalas)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 494, Short.MAX_VALUE)
                                .add(confirmarSala, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(cancelarSala, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())
                    .add(layout.createSequentialGroup()
                        .add(tituloconfirmadas)
                        .addContainerGap(621, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(titulo)
                    .add(juser, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jiduser))
                .add(8, 8, 8)
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(titulosalas)
                    .add(cancelarSala)
                    .add(confirmarSala))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 218, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(tituloconfirmadas)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 148, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(48, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void salaCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salaCancelarActionPerformed
        // TODO add your handling code here:
        List<Reserva> lista;
        List<Sala> lista1 = new ArrayList<Sala>();
        Sala sala = new Sala();

        int lin = tabsala.getSelectedRow();


        if(lin<0){
            Main.log.warning("O usuario: "+usuario+", tentou cancelar uma solicitação sem selecionar uma!");
            if(idioma.equals("en_US")){
                JOptionPane.showMessageDialog(null, "You have to select a classroom first, than cancel it!", "ERROR!", JOptionPane.ERROR_MESSAGE);
            }else{
                JOptionPane.showMessageDialog(null, "Você tem que selecionar um sala para então cancelar!", "ERRO!", JOptionPane.ERROR_MESSAGE);
            }
        }else{
            int j;
            int idS = Integer.parseInt(tabsala.getValueAt(lin, 0).toString());

            if(idioma.equals("en_US")){
                Object[] options = {"Yes","No"};
                j = JOptionPane.showOptionDialog(null,
                                "Do you really want to deny this solicitation?",
                                "Deny Solicitation",
                                JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE,
                                null,
                                options,
                                options[1]);
            }
            else{
                Object[] options = {"Sim","Não"};
                j = JOptionPane.showOptionDialog(null,
                                "Deseja realmente negar está solicitação?",
                                "Negar Solicitação",
                                JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE,
                                null,
                                options,
                                options[1]);
                }
            if (j==JOptionPane.YES_OPTION){
               try{
                    ReservaDAO resd = new ReservaDAO();
                    SalaDAO salad = new SalaDAO();

                    resd.negarSolic(idS);

                    lista = resd.reservaListaSalaTudo();
                    int tam = lista.size();

                    int ids[] = new int[tam];

                    for(int i=0;i<lista.size();i++){
                        ids[i] = lista.get(i).getIdsala();
                    }

                    for(int i=0;i<lista.size();i++){
                        sala = salad.sala(ids[i]);
                        lista1.add(sala);
                    }
                    
                    preenhcerTabelaReservas();
                    preencherTabelaSala(lista, lista1);
                    Main.log.info("O usuario: "+usuario+", cancelou com sucesso a solicitação de numero: "+idS);
                }catch(SQLException e){
                    e.printStackTrace();
                    Main.log.severe("O usuario: "+usuario+", teve um problema e não conseguiu cancelar a solicitação de numero: "+idS);
                }
            }
        }   
    }//GEN-LAST:event_salaCancelarActionPerformed

    private void formAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_formAncestorAdded
        // TODO add your handling code here:
        List<Reserva> lista;
        List<Sala> lista1 = new ArrayList<Sala>();
        Sala sala = new Sala();

        tabsala1.setEnabled(false);
        preenhcerTabelaReservas();

        try{
            ReservaDAO resd = new ReservaDAO();
            SalaDAO salad = new SalaDAO();
            lista = resd.reservaListaSalaTudo();
            int tam = lista.size();

            int ids[] = new int[tam];

            for(int i=0;i<lista.size();i++){
                ids[i] = lista.get(i).getIdsala();
            }

            for(int i=0;i<lista.size();i++){
                sala = salad.sala(ids[i]);
                lista1.add(sala);
            }

            preencherTabelaSala(lista, lista1);
        }catch(SQLException e){
            e.printStackTrace();
        }
    }//GEN-LAST:event_formAncestorAdded

    private void tabsalaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabsalaMouseClicked
        // TODO add your handling code here:
        int lin = tabsala.getSelectedRow();
        int col = tabsala.getSelectedColumn();

        if(lin>0 && col>0){
            cancelarSala.setEnabled(true);
        }
        if(evt.getButton() == java.awt.event.MouseEvent.BUTTON1 && evt.getClickCount() == 2){
            popsala.show(tabsala, evt.getX(), evt.getY());
            idSolic = Integer.parseInt(tabsala.getValueAt(lin, 0).toString());
        }else{
            idSolic = Integer.parseInt(tabsala.getValueAt(lin, 0).toString());
        }
}//GEN-LAST:event_tabsalaMouseClicked

    private void formComponentAdded(java.awt.event.ContainerEvent evt) {//GEN-FIRST:event_formComponentAdded
        // TODO add your handling code here:
    }//GEN-LAST:event_formComponentAdded

    private void cancelarSalaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarSalaActionPerformed
        // TODO add your handling code here:
        List<Reserva> lista;
        List<Sala> lista1 = new ArrayList<Sala>();
        Sala sala = new Sala();

        int lin = tabsala.getSelectedRow();


        if(lin<0){
            Main.log.warning("O usuario: "+usuario+", tentou cancelar uma solicitação sem selecionar uma!");
            if(idioma.equals("en_US")){
                JOptionPane.showMessageDialog(null, "You have to select a classroom first, than cancel it!", "ERROR!", JOptionPane.ERROR_MESSAGE);
            }else{
                JOptionPane.showMessageDialog(null, "Você tem que selecionar um sala para então cancelar!", "ERRO!", JOptionPane.ERROR_MESSAGE);
            }
        }else{
            int j;
            int idS = Integer.parseInt(tabsala.getValueAt(lin, 0).toString());

            if(idioma.equals("en_US")){
                Object[] options = {"Yes","No"};
                j = JOptionPane.showOptionDialog(null,
                                "Do you really want to deny this solicitation?",
                                "Deny Solicitation",
                                JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE,
                                null,
                                options,
                                options[1]);
            }
            else{
                Object[] options = {"Sim","Não"};
                j = JOptionPane.showOptionDialog(null,
                                "Deseja realmente negar está solicitação?",
                                "Negar Solicitação",
                                JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE,
                                null,
                                options,
                                options[1]);
                }
            if (j==JOptionPane.YES_OPTION){
               try{
                    ReservaDAO resd = new ReservaDAO();
                    SalaDAO salad = new SalaDAO();

                    resd.negarSolic(idS);

                    lista = resd.reservaListaSalaTudo();
                    int tam = lista.size();

                    int ids[] = new int[tam];

                    for(int i=0;i<lista.size();i++){
                        ids[i] = lista.get(i).getIdsala();
                    }

                    for(int i=0;i<lista.size();i++){
                        sala = salad.sala(ids[i]);
                        lista1.add(sala);
                    }

                    preenhcerTabelaReservas();
                    preencherTabelaSala(lista, lista1);
                    Main.log.info("O usuario: "+usuario+", cancelou com sucesso a solicitação de numero: "+idS);
                }catch(SQLException e){
                    e.printStackTrace();
                    Main.log.severe("O usuario: "+usuario+", teve um problema e não conseguiu cancelar a solicitação de numero: "+idS);
                }
            }
        }

        
    }//GEN-LAST:event_cancelarSalaActionPerformed

    private void salaConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salaConfirmarActionPerformed
        // TODO add your handling code here:
        List<Reserva> lista;
        List<Sala> lista1 = new ArrayList<Sala>();
        Sala sala = new Sala();

        int lin = tabsala.getSelectedRow();

        if(lin<0){
            Main.log.warning("O usuario: "+usuario+", tentou confirmar uma solicitação sem selecionar uma!");
            if(idioma.equals("en_US")){
                JOptionPane.showMessageDialog(null, "You have to select a classroom first, than confirm it!", "ERROR!", JOptionPane.ERROR_MESSAGE);
            }else{
                JOptionPane.showMessageDialog(null, "Você tem que selecionar um sala para então confirmar!", "ERRO!", JOptionPane.ERROR_MESSAGE);
            }
        }else{
            int j;
            int idS = Integer.parseInt(tabsala.getValueAt(lin, 0).toString());

            if(idioma.equals("en_US")){
                Object[] options = {"Yes","No"};
                j = JOptionPane.showOptionDialog(null,
                                "Do you really want to confirm this solicitation?",
                                "Confirm Solicitation",
                                JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE,
                                null,
                                options,
                                options[1]);
            }
            else{
                Object[] options = {"Sim","Não"};
                j = JOptionPane.showOptionDialog(null,
                                "Deseja realmente confirmar está solicitação?",
                                "Confirmar Solicitação",
                                JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE,
                                null,
                                options,
                                options[1]);
                }
            if (j==JOptionPane.YES_OPTION){
                try{
                    ReservaDAO resd = new ReservaDAO();
                    SalaDAO salad = new SalaDAO();

                    resd.confirmarSolic(idS);

                    lista = resd.reservaListaSalaTudo();
                    int tam = lista.size();

                    int ids[] = new int[tam];

                    for(int i=0;i<lista.size();i++){
                        ids[i] = lista.get(i).getIdsala();
                    }

                    for(int i=0;i<lista.size();i++){
                        sala = salad.sala(ids[i]);
                        lista1.add(sala);
                    }

                    preenhcerTabelaReservas();
                    preencherTabelaSala(lista, lista1);
                    Main.log.info("O usuario: "+usuario+", confirmou com sucesso a solicitação de numero: "+idS);
                }catch(SQLException e){
                    e.printStackTrace();
                    Main.log.severe("O usuario: "+usuario+", teve um problema e não conseguiu confirmar a solicitação de numero: "+idS);
                }
            }
        }
    }//GEN-LAST:event_salaConfirmarActionPerformed

    private void confirmarSalaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmarSalaActionPerformed
        // TODO add your handling code here:
        List<Reserva> lista;
        List<Sala> lista1 = new ArrayList<Sala>();
        Sala sala = new Sala();

        int lin = tabsala.getSelectedRow();

        if(lin<0){
            Main.log.warning("O usuario: "+usuario+", tentou confirmar uma solicitação sem selecionar uma!");
            if(idioma.equals("en_US")){
                JOptionPane.showMessageDialog(null, "You have to select a classroom first, than confirm it!", "ERROR!", JOptionPane.ERROR_MESSAGE);
            }else{
                JOptionPane.showMessageDialog(null, "Você tem que selecionar um sala para então confirmar!", "ERRO!", JOptionPane.ERROR_MESSAGE);
            }
        }else{
            int j;
            int idS = Integer.parseInt(tabsala.getValueAt(lin, 0).toString());

            if(idioma.equals("en_US")){
                Object[] options = {"Yes","No"};
                j = JOptionPane.showOptionDialog(null,
                                "Do you really want to confirm this solicitation?",
                                "Cancel Solicitation",
                                JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE,
                                null,
                                options,
                                options[1]);
            }
            else{
                Object[] options = {"Sim","Não"};
                j = JOptionPane.showOptionDialog(null,
                                "Deseja realmente confirmar está solicitação?",
                                "Cancelar Solicitação",
                                JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE,
                                null,
                                options,
                                options[1]);
                }
            if (j==JOptionPane.YES_OPTION){
                try{
                    ReservaDAO resd = new ReservaDAO();
                    SalaDAO salad = new SalaDAO();

                    resd.confirmarSolic(idS);

                    lista = resd.reservaListaSalaTudo();
                    int tam = lista.size();

                    int ids[] = new int[tam];

                    for(int i=0;i<lista.size();i++){
                        ids[i] = lista.get(i).getIdsala();
                    }

                    for(int i=0;i<lista.size();i++){
                        sala = salad.sala(ids[i]);
                        lista1.add(sala);
                    }

                    preenhcerTabelaReservas();
                    preencherTabelaSala(lista, lista1);
                    Main.log.info("O usuario: "+usuario+", confirmou com sucesso a solicitação de numero: "+idS);
                }catch(SQLException e){
                    e.printStackTrace();
                    Main.log.severe("O usuario: "+usuario+", teve um problema e não conseguiu confirmar a solicitação de numero: "+idS);
                }
            }
        }
    }//GEN-LAST:event_confirmarSalaActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelarSala;
    private javax.swing.JButton confirmarSala;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel jiduser;
    private javax.swing.JLabel juser;
    private javax.swing.JPopupMenu popsala;
    private javax.swing.JMenuItem salaCancelar;
    private javax.swing.JMenuItem salaConfirmar;
    private javax.swing.JTable tabsala;
    private javax.swing.JTable tabsala1;
    private javax.swing.JLabel titulo;
    private javax.swing.JLabel tituloconfirmadas;
    private javax.swing.JLabel titulosalas;
    // End of variables declaration//GEN-END:variables

    public void preenhcerTabelaReservas(){
        List<Reserva> lista;
        List<Sala> lista1 = new ArrayList<Sala>();
        Sala sala = new Sala();

        try{
            ReservaDAO resd = new ReservaDAO();
            SalaDAO salad = new SalaDAO();

            lista = resd.reservaListaSalaTudoReserva();
            int tam = lista.size();

            int ids[] = new int[tam];

            for(int i=0;i<lista.size();i++){
                ids[i] = lista.get(i).getIdsala();
            }

            for(int i=0;i<lista.size();i++){
                sala = salad.sala(ids[i]);
                lista1.add(sala);
            }

            preencherTabelaSala1(lista, lista1);
        }catch(SQLException e){
            e.printStackTrace();
        }

    }

    public void preencherTabelaSala(List<Reserva> lista, List<Sala> lista1){

        DefaultTableModel tabela = (DefaultTableModel) tabsala.getModel();

        while (tabela.getRowCount() > 0) { //vai pegar todas as linha selecionadas maiores que zero, é vai remove-las!
            tabela.removeRow(0);
        }

        String[] linha = new String[]{null, null, null, null, null, null, null, null, null};
        for (int i = 0; i < lista.size(); i++) {
            tabela.addRow(linha);
            tabela.setValueAt(lista.get(i).getIdreserva(), i, 0);
            tabela.setValueAt(lista.get(i).getIdsala(), i, 1);
            tabela.setValueAt(lista.get(i).getIdusuario(), i, 2);
            tabela.setValueAt(lista1.get(i).getQtdlugares(), i, 3);
            tabela.setValueAt(lista1.get(i).getLocalsala(), i, 4);
            tabela.setValueAt(lista1.get(i).getTiposala(), i, 5);
            tabela.setValueAt(lista.get(i).getData(), i, 6);
            tabela.setValueAt(horario[lista.get(i).getHora() - 1], i, 7);
        }
    }

    public void preencherTabelaSala1(List<Reserva> lista, List<Sala> lista1){

        DefaultTableModel tabela = (DefaultTableModel) tabsala1.getModel();

        while (tabela.getRowCount() > 0) { //vai pegar todas as linha selecionadas maiores que zero, é vai remove-las!
            tabela.removeRow(0);
        }

        String[] linha = new String[]{null, null, null, null, null, null, null, null, null};
        for (int i = 0; i < lista.size(); i++) {
            tabela.addRow(linha);
            tabela.setValueAt(lista.get(i).getIdreserva(), i, 0);
            tabela.setValueAt(lista.get(i).getIdsala(), i, 1);
            tabela.setValueAt(lista.get(i).getIdusuario(), i, 2);
            tabela.setValueAt(lista1.get(i).getQtdlugares(), i, 3);
            tabela.setValueAt(lista1.get(i).getLocalsala(), i, 4);
            tabela.setValueAt(lista1.get(i).getTiposala(), i, 5);
            tabela.setValueAt(lista.get(i).getData(), i, 6);
            tabela.setValueAt(horario[lista.get(i).getHora() - 1], i, 7);
        }
    }

    public void internacionaliza(){
        ResourceBundle palavras = ResourceBundle.getBundle("idiomas.Lingua_"+idioma);

        titulo.setText(palavras.getString("verificar.titulogerenciarS"));
        titulosalas.setText(palavras.getString("verificar.titulosala"));
        juser.setText(palavras.getString("verificar.user"));
        cancelarSala.setText(palavras.getString("gerenciarEquip.negar"));
        salaCancelar.setText(palavras.getString("gerenciarEquip.negar"));
        confirmarSala.setText(palavras.getString("gerenciarEquip.confirmar"));
        salaConfirmar.setText(palavras.getString("gerenciarEquip.confirmar"));
    tituloconfirmadas.setText(palavras.getString("gerenciar.tituloconfirmadas"));

        headerSala[0] = palavras.getString("verificar.idsolic");
        headerSala[1] = palavras.getString("verificar.idsala");
        headerSala[2] = palavras.getString("verificar.iduser");
        headerSala[3] = palavras.getString("verificar.lugares");
        headerSala[4] = palavras.getString("verificar.local");
        headerSala[5] = palavras.getString("verificar.tipo");
        headerSala[6] = palavras.getString("verificar.data");
        headerSala[7] = palavras.getString("verificar.horario");

    }

    public void organizarHeaders(){
        for(int i=0;i<8;i++){
            tabsala.getTableHeader().setFont(new java.awt.Font(""+headerSala[i],java.awt.Font.PLAIN, 11));
            tabsala.getColumnModel().getColumn(i).setHeaderValue(""+headerSala[i]);
        }

        for(int i=0;i<8;i++){
            tabsala1.getTableHeader().setFont(new java.awt.Font(""+headerSala[i],java.awt.Font.PLAIN, 11));
            tabsala1.getColumnModel().getColumn(i).setHeaderValue(""+headerSala[i]);
        }
    }
}
